﻿using log4net;
using log4net.Config;
using log4net.Layout;
using log4net.Repository.Hierarchy;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Kimd.Common
{
    public class LogHelper : SingletonProvider<LogHelper>
    {
        private readonly log4net.ILog appLog = LogManager.GetLogger("logApp");
        private readonly log4net.ILog debugLog = LogManager.GetLogger("debugApp");
        private readonly log4net.ILog ctLog = LogManager.GetLogger("ctApp");

        public LogHelper()
        {
        }

        public ILog GetLog(string logName)
        {
            return LogManager.GetLogger(logName);
        }

        public void Log(string source, string message, MessageLevel level, Exception exception = null)
        {
            switch(level)
            {
                case MessageLevel.Error:
                    appLog.Error($"[{source}] {message}", exception);
                    break;
                case MessageLevel.Warn:
                    appLog.Warn($"[{source}] {message}");
                    break;
                case MessageLevel.Log:
                    appLog.Info($"[{source}] {message}");
                    break;
                case MessageLevel.Mes:
                    debugLog.Debug($"[{source}] {message}", exception);
                    break;
                case MessageLevel.CT:
                    ctLog.Info($"[{source}] {message}");
                    break;
            }
        }
    }

    public enum MessageLevel
    {
        Log,
        Mes,
        CT,
        Warn,
        Error, 
        InfoAndPause
    }
 }
